var app = getApp();
import {
  user,
  merchantUpdate,
  merchantProfile
} from "../../api.js"
Page({

  data: {
    spn:"",
    titt:false,
    titles:{
      tit1:"您还未开通资金账户，这将影响您正常收款和提现",
      tit3:"立即开通"
    },
    showname:false,
    url3:"https://resource.growthupup.com/icon_edit@2x.png",
    url2:"https://resource.growthupup.com/icon_verified@2x.png",
    weixin:"Brandx11",
    showtext:false,
    brandTv: true,
    url:"https://resource.growthupup.com/cha.png?t=2",
    is_auth:"",
    is_identify:"",
    is_bank_auth:"",
    show: false,
    name: true,
    shopname: "",
    input: "",
    changeid:false,
    is_name_updated:"",
    moneybank:true
  },
  closemoney(){
    this.setData({
      moneybank:true
    })
  },
  gople(){
    this.setData({
      moneybank:true
    })
   wx.navigateTo({
     url: 'setUp/certification/certification',
   })
  },
  bill: function () {
    if (this.data.is_auth == 0 || this.data.is_identify == 0 || this.data.is_bank_auth==0){
      this.setData({
        moneybank:false
      })
    }else{
      wx.navigateTo({
        url: '/pages/user/bill/bill',
        success: function (res) { },
        fail: function (res) { },
        complete: function (res) { },
      })
    }
    
  },
  set() {
   wx.navigateTo({
     url: 'setUp/setUp?is_auth=' + this.data.is_auth + "&is_identify=" + this.data.is_identify + "&is_bank_auth=" + this.data.is_bank_auth,
   })
  },
  //直播
  brandtv(){
    this.setData({
      brandTv:false,
      show:true
    })
  },
  closebrand(){
    this.setData({
      brandTv:true,
      show:false
    })
  },
  //复制
  copy(){
    var that =this
    wx.setClipboardData({
      data: this.data.weixin,
      success(res) {
        wx.getClipboardData({
          success(res) {
            console.log(res.data) // data
            that.setData({
              brandTv:true,
              show:false
            })
          }
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      is_name_updated:app.globalData.is_name_updated
    })

    
  },
  getshopname(){
    merchantProfile({
      token: app.globalData.token,
    }).then(res => {
      if (res.data.code === 666) {
        console.log("res")
        console.log(res)
        if (res.data.data[0].merFullName) {
          this.setData({
            shopname: res.data.data[0].merFullName,
            is_auth: res.data.data[0].is_auth,
            is_identify: res.data.data[0].is_identify,
            is_bank_auth: res.data.data[0].is_bank_auth
          })
          if (res.data.data[0].is_auth == 0 || res.data.data[0].is_identify==0 || res.data.data[0].is_bank_auth==0){
            this.setData({
              showname:true,
              titles: {
                tit1: "您还未开通资金账户",
                tit2: "，这将影响您正常收款和提现",
                tit3: "立即开通"
              }
            })
          }
        }
        if(res.data.data[0].is_auth == 3){
          this.setData({
            showname:true,
            titles: {
              tit1: "您在开通资金账户时",
              tit2: "，认证失败请联系客服查看原因",
              tit3: "重新开通"
            }
          })
        }
        // 0 未认证 1 正在认证审核中 2 认证成功
        if (res.data.data.is_auth == 0 && res.data.data.is_auth !=3) {
          this.setData({
            changeid: true
          })
        } 
        // 个人身份信息是否提交 0未提交 1 已提交
      }

    })
  },
  // 跳转至认证页面
  gorenzheng(){
    if (this.data.is_auth == 3){
      wx.navigateTo({
        url: '../user/setUp/certification/myenterprise/myenterprise',
      })
    }
    if (this.data.is_identify === 0){
      wx.navigateTo({
        url: '../user/setUp/certification/myenterprise/myenterprise',
      })
    } else if (this.data.is_bank_auth ===0){
      wx.navigateTo({
        url: '../user/setUp/certification/second/second',
      })
    }else{
      this.setData({
        changeid:true
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    let _this = this;
    user({
      token: app.globalData.token
    }).then(res => {
      if (res.data.code == 666) {
        if (res.data.data[0] === null) {
          
        }
        return
      }
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getshopname();
    console.log(app.globalData.is_name_updated)
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },
  hidden() {
    this.setData({
      show: false,
      showtext:false
    })
  },
  showtext() {
    if(this.data.changeid){
      return
    }else{
      this.setData({
        show: true,
        showtext:true
      })
    }
   
  },
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
  gointlist() {
    wx.navigateTo({
      url: '../orderControl/orderControl',
    })
  },
  shopdizhi() {
    wx.navigateTo({
      url: '/pages/user/setUp/myadd/myadd?addChoice=1',
    })
  },
  kucunguanli() {
    wx.navigateTo({
      url: 'myOrder/myOrder',
    })
  },
  //设置商铺名字
  setname(e) {
    this.setData({
      titt: true
    })
  },
  setnewname(e) {
    this.setData({
      spn: e.detail.value
    })
  },
  //修改商户名称
  changename(){
    this.setData({
      show:false,
      showtext:false
    })
    if (this.data.input == "可输入中文或英文商铺名"){
      wx.showToast({
        title: '请输入正确商户名',
        icon:"none"
      })
    }
    merchantUpdate({
      token:app.globalData.token,
      shopname: this.data.spn
    }).then(res=>{
      if(res.data.code==666){
        this.getshopname()
      }
    })
  },
  //发送新用户名到后端
  sendname() {
    this.hidden()
  },
 
  //跳入直播

  //去购物车
  goshopcar(){
    wx.navigateTo({
      url: 'shopCar/shopCar?color='+false,
    })
  },

  /**
   * 用户点击右上角分享
   */

  onShareAppMessage: function (res) {
    var that = this;
    var goods_title = '赋能奢商，只为业绩增长';//获取产品标题
    var goods_img = "https://document.growthupup.com/growthShare.jpg?t=" + new Date().getTime()
    return {
      title: goods_title,
      path: '/pages/loading/loading',
      imageUrl: goods_img //不设置则默认为当前页面的截图
    }
  }
})